package day7;

import java.time.Year;
import java.util.*;

//a.实现斗地主随机发牌的功能 一共54张牌
//        牌的花色分为   梅花   红桃   黑桃  方片
//        牌有  3  4 5 6 7 8 9 10 J  Q K  A  2  大王 小王
//        随机发给两个农民 和一个地主      地主 多三张牌
//        最后显示每人的牌的结果  并且每人的排要根据牌的大小进行降序排列
public class Home {
    public static void main(String[] args) {
        //demo();
        demo1();
    }
    public static void demo(){
        //Set<CardDemo> set=new TreeSet<>();
        String[] colors={"♣","♥","♠","♦"};//花色
        String[] nums={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};//牌值
        List<CardDemo> cards=new ArrayList<>();
        for(String s:colors){
            for(int i=0;i<nums.length;i++){
              cards.add(new CardDemo(s+nums[i],i+3));
            }
        }
        cards.add(new CardDemo("小🃏",16));
        cards.add(new CardDemo("大🃏",17));
        Collections.shuffle(cards);//打乱顺序
        List<CardDemo> last5=cards.subList(51,54);
        List<CardDemo> richer=cards.subList(34,51);
        richer.addAll(last5);
        List<CardDemo> farmer1=cards.subList(0,17);
        List<CardDemo> farmer2=cards.subList(17,34);
        // 创建Comparator
        Comparator<CardDemo> desc = (card1,card2) -> {
            int i=card2.num-card1.num;
            if(i==0) card1.str.compareTo(card2.str);
            return i;
        };
        // 使用Comparator排序
        Collections.sort(farmer1, desc);
        Collections.sort(farmer2, desc);
        Collections.sort(richer, desc);
        System.out.println("农民1的牌"+farmer1);
        System.out.println("农民2的牌"+farmer2);
        System.out.println("地主的牌"+richer);
    }
    public static void demo1(){
        Map<Integer,WorldCup> worldCups=new HashMap<>();
        // 使用put方法添加数据
        worldCups.put(1930, new WorldCup(1, "乌拉圭", "乌拉圭"));
        worldCups.put(1934, new WorldCup(2, "意大利", "意大利"));
        worldCups.put(1938, new WorldCup(3, "法国", "意大利"));
        worldCups.put(1950, new WorldCup(4, "巴西", "乌拉圭"));
        worldCups.put(1954, new WorldCup(5, "瑞士", "西德"));
        worldCups.put(1958, new WorldCup(6, "瑞典", "巴西"));
        worldCups.put(1962, new WorldCup(7, "智利", "巴西"));
        worldCups.put(1966, new WorldCup(8, "英格兰", "英格兰"));
        worldCups.put(1970, new WorldCup(9, "墨西哥", "巴西"));
        worldCups.put(1974, new WorldCup(10, "前西德", "西德"));
        worldCups.put(1978, new WorldCup(11, "阿根廷", "阿根廷"));
        worldCups.put(1982, new WorldCup(12, "西班牙", "意大利"));
        worldCups.put(1986, new WorldCup(13, "墨西哥", "阿根廷"));
        worldCups.put(1990, new WorldCup(14, "意大利", "西德"));
        worldCups.put(1994, new WorldCup(15, "美国", "巴西"));
        worldCups.put(1998, new WorldCup(16, "法国", "法国"));
        worldCups.put(2002, new WorldCup(17, "韩日", "巴西"));
        worldCups.put(2006, new WorldCup(18, "德国", "意大利"));
        worldCups.put(2010, new WorldCup(19, "南非", "西班牙"));
        worldCups.put(2014, new WorldCup(20, "巴西", "德国"));
        worldCups.put(2018, new WorldCup(21, "俄罗斯", "法国"));
        worldCups.put(2022, new WorldCup(22, "卡塔尔", "阿根廷"));
        System.out.println("请输入年份：");
        Scanner sc=new Scanner(System.in);
        Integer year2=sc.nextInt();
        if(worldCups.containsKey(year2)){
            String champion=worldCups.get(year2).champion;
            System.out.println(year2+"冠军是："+champion);
        }else{
            System.out.println("您输入的年份不匹配");
        }
        System.out.println("请输入您要查询球队的名字:");
        String name=sc.next();
        Iterator<Map.Entry<Integer,WorldCup>> it=worldCups.entrySet().iterator();
        //entrySet() 获取map中key和value的集合
        boolean b=false;
        while(it.hasNext()){
            Map.Entry<Integer,WorldCup> e=it.next();
            int year1=e.getKey();
            WorldCup wc=e.getValue();
            if(wc.getChampion().equals(name)){
                System.out.println(year1+"");
                b=true;
            }
        }
        if(!b){
            System.out.println("您输入的球队没获得过！");
        }
    }
}
class CardDemo{
    String str;//存储的内容
    int num;//牌号
    public CardDemo( String str,int num) {
        this.str = str;
        this.num = num;
    }
    @Override
    public String toString() {
        return str;
    }
}
class WorldCup{
      int year;
      String place;//地点
      String champion;//冠军
    public WorldCup(int year, String place, String champion) {
        this.year = year;
        this.place = place;
        this.champion = champion;
    }
    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place =place;
    }

    public String getChampion() {
        return champion;
    }

    public void setChampion(String champion) {
        this.champion = champion;
    }
}